/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.img;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/**
 * <p>Project: app2022 - Ex9
 * <p>Powered by webrx On 2022-01-24 17:49:36
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex9 {
    public static long rows = 0;

    public static void main(String[] args) {

        System.out.println(countDirRows(new File(System.getProperty("user.dir"))));

    }


    public static long countSourceRows(File file) {
        long rows = 0;
        try (BufferedReader br = new BufferedReader(new FileReader(file))) {
            rows = br.lines().count();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return rows;
    }

    public static long countDirRows(File dir) {
        for (File f : dir.listFiles()) {
            if (f.isDirectory()) {
                countDirRows(f);
            } else if (f.isFile() && f.getName().endsWith(".java")) {
                rows += countSourceRows(f);
            }
        }
        return rows;
    }
}
